package com.yuandian.bpm.bi.modules.user.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.bpm.bi.modules.user.entity.ConfAddresseeApp;
import com.yuandian.bpm.bi.modules.user.entity.ConfAddresser;
import com.yuandian.bpm.bi.modules.user.service.ConfAddresserService;
import com.yuandian.bpm.bi.modules.user.vo.ConfAddresserVo;
import com.yuandian.bpm.common.core.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 推送对象_应用-Controller
 * @author zfsn
 * @date 2023-7-4
 */
@Api(tags = "全局设置-发送邮箱设置-发件人")
@RestController
@RequestMapping("/confAddresser")
public class ConfAddresserController {

	@Autowired
	private ConfAddresserService confAddresserService;

	/**
	 * 通过主键查询数据
	 *
	 * @param id 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键查询数据", notes = "通过主键查询数据，不支持批量查询")
	@GetMapping("/{id}")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "id", paramType = "path", required = false, dataTypeClass = Integer.class),
	})
	public R<ConfAddresser> queryByIds(@PathVariable("id") @ApiIgnore Integer id) {
		return R.ok(confAddresserService.getById(id));
	}

	/**
	 * 分页查询
	 *
	 * @param
	 * @param confAddresserVo 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@PostMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "pageNum", value = "当前页数", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "orderByColumn", value = "排序列", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "isAsc", value = "排序的方向值只能是 desc 或者 asc", paramType = "body", required = true, dataType = "String")
	})
	public R<Page<ConfAddresseeApp>> listPage(@RequestBody @ApiIgnore ConfAddresserVo confAddresserVo) {
		return R.ok(confAddresserService.listPage(confAddresserVo));
	}

	/**
	 * 新增数据
	 *
	 * @param confAddresser 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增数据", notes = "新增数据")
	@PostMapping("/save")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "email", value = "邮箱", paramType = "body", required = true, dataTypeClass = String.class),
			@ApiImplicitParam(name = "nickName", value = "显示名称", paramType = "body", required = true, dataTypeClass = String.class),
			@ApiImplicitParam(name = "emailHost", value = "邮件服务器", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "emailPort", value = "端口", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "encryptType", value = "加密方式, 1:SSL  2:TLS 加密 3:不加密", paramType = "body", required = true,  dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "password", value = "密码", paramType = "body", required = true,  dataTypeClass = String.class),
			@ApiImplicitParam(name = "isDefault", value = "是否是默认发件人, 0 否,1是", paramType = "body", required = true,  dataTypeClass = Integer.class),
	})
	public R<String> save(@RequestBody @ApiIgnore ConfAddresser confAddresser) {
		return confAddresserService.saveData(confAddresser);
	}

	/**
	 * 通过主键更新数据
	 *
	 * @param confAddresser 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键更新数据", notes = "通过主键更新数据")
	@PutMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "id", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "email", value = "邮箱", paramType = "body", required = true, dataTypeClass = String.class),
			@ApiImplicitParam(name = "nickName", value = "显示名称", paramType = "body", required = true, dataTypeClass = String.class),
			@ApiImplicitParam(name = "emailHost", value = "邮件服务器", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "emailPort", value = "端口", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "encryptType", value = "加密方式, 1:SSL  2:TLS 加密 3:不加密", paramType = "body", required = true,  dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "password", value = "密码", paramType = "body", required = true,  dataTypeClass = String.class),
			@ApiImplicitParam(name = "isDefault", value = "是否是默认发件人, 0 否,1是", paramType = "body", required = true,  dataTypeClass = Integer.class),
	})
	public R<String> updateById(@RequestBody @ApiIgnore ConfAddresser confAddresser) {
		return confAddresserService.updateDataById(confAddresser);
	}

	/**
	 * 通过主键删除数据
	 *
	 * @param id 主键
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键删除数据", notes = "通过主键删除数据")
	@DeleteMapping("/delete/{id}")
	public R<String> removeById(@PathVariable("id") Integer id) {
		confAddresserService.removeById(id);
		return R.ok();
	}

	/**
	 * 默认发件人
	 *
	 * @param id 主键
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "默认发件人", notes = "默认发件人")
	@GetMapping("/defaultSender/{id}")
	public R<String> defaultSender(@PathVariable("id") Integer id) {
		return confAddresserService.defaultSender(id);
	}

}
